package com.elinkway.infinitemovies.http.parser;

import android.text.TextUtils;

import com.elinkway.infinitemovies.bean.LiteAppLinkUrlInfo;
import com.elinkway.infinitemovies.service.UpdateService;
import com.elinkway.infinitemovies.utils.LogUtils;

import org.json.JSONObject;

/**
 * Created by 吴新荣 on 2015/12/28.
 * LiteApp下载链接Jason解析器
 */
public class LiteAppLinkUrlParser extends LVideoMobileParser<LiteAppLinkUrlInfo> {

    private static final String STATUS = "status";
    private static final String DOWNLOAD_URL = "url";
    private static final String MD5 = "md5";

    @Override
    public LiteAppLinkUrlInfo parse(JSONObject data) throws Exception {

        LiteAppLinkUrlInfo info = new LiteAppLinkUrlInfo();
        String status = null;
        String url = null;
        try {
            JSONObject result = getJSONObject(data, "header");
            if (null != result) {
                status = getString(result, STATUS);
                if (!TextUtils.isEmpty(status) && status.equals("1")) {
                    info.setStatus(status);
                    result = getJSONObject(data, "body");
                    if (null != result) {
                        url = getString(result, DOWNLOAD_URL);
                        LogUtils.e(UpdateService.TAG, "parser DOWNLOAD_URL is " + url);
                        info.setUrl(url);
                        info.setMd5(getString(result, MD5));
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return info;
    }
}
